package com.gexin.model.notice;

import com.gexin.common.utils.SQLUtils;
import com.gexin.model.notice.base.BaseNoticeType;
import com.jfinal.plugin.activerecord.Page;
import org.apache.commons.lang3.StringUtils;

import java.util.LinkedList;
import java.util.List;

/**
 * 业务名称:  t_notice_type(公告类型) 
 */
@SuppressWarnings("serial")
public class NoticeType extends BaseNoticeType<NoticeType> {
	public static final NoticeType dao = new NoticeType();

	public Page<NoticeType> query(int pageNumber,int pageSize,NoticeType type){
		List<Object> list =new LinkedList<Object>();
		SQLUtils sql=new SQLUtils(" from  t_notice_type  where 1=1 ");
		if(type!=null){
			if(type.getNoticeType()!=null){
				sql.append(" and notice_type = ? ");
				list.add(type.getNoticeType());
			}
			if(!StringUtils.isEmpty(type.getTypeName())){
				sql.append(" and  type_name like ? ");
				list.add("%"+type.getTypeName()+"%");
			}
			if(type.getState()!=null){
				sql.append(" and state = ? ");
				list.add(type.getState());
			}
		}
		sql.append(" order by create_time desc ");
		return paginate(pageNumber,pageSize,"select * ",sql.toString(),list.toArray());
	}

	public List<NoticeType> findByNoticeType(int notice_type){
		return dao.find("select * from  t_notice_type  where state =0 and notice_type = ?  ",notice_type);
	}

}
